home *** CD-ROM | disk | FTP | other *** search
- page 62, 132
- title Bit test and manipulation routines for BASIC
- subttl By Jim Mack, Editing Services Co.
-
- comment |
-
- Implements bit set/clear/test for QB/BC.
-
- Four procedures are declared in BASIC:
-
- DECLARE SUB SetBit (bitnum%, word%)
- DECLARE SUB ClearBit (bitnum%, word%)
- DECLARE SUB ToggleBit (bitnum%, word%)
- DECLARE FUNCTION BitState% (bitnum%, word%)
-
- BITNUM% is the selected bit position, numbered 1 through 16
- WORD% is the 16 bit quantity where the bit resides,
-
- SetBit sets the selected bit to 1
- ClearBit sets it to 0
- ToggleBit changes it to 0 if it is now 1, and vice versa
- BitState returns TRUE (-1) if the bit is set, FALSE (0) if not.
-
- | comment ends
-
- page+
- .model medium, basic
- .code
-
- BitCommon PROC NEAR
-
- wd equ 6[bp] ; repeat the stack equates from the FAR PROCs
- bitnum equ 8[bp]
-
- mov bx, bitnum
- mov cx, [bx]
- dec cx ; remove this for bit number range 0-15
- mov ax, 1
- shl ax, cl
- mov bx, wd
- ret
-
- BitCommon ENDP
- page+
- SetBit PROC bitnum, wd
-
- call BitCommon
- or [bx], ax
- ret
-
- SetBit ENDP
-
- ClearBit PROC bitnum, wd
-
- call BitCommon
- not ax
- and [bx], ax
- ret
-
- ClearBit ENDP
-
- ToggleBit PROC bitnum, wd
-
- call BitCommon
- xor [bx], ax
- ret
-
- ToggleBit ENDP
-
- BitState PROC bitnum, wd
-
- call BitCommon
- xor cx, cx
- test [bx], ax
- mov ax, cx
- jz @f
- dec ax
- @@: ret
-
- BitState ENDP
-
- END